package com.lzc.test.controller;

import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lzc.test.common.ResultCode;
import com.lzc.test.entity.request.LoginRequest;
import com.lzc.test.entity.response.LoginResponse;
import com.lzc.test.svc.serviceImpl.LoginImpl;

@Controller
public class Login {
	
	@Resource
	LoginImpl loginImpl;
	
	@RequestMapping(value = "/login", method = RequestMethod.POST)
	@ResponseBody
	public LoginResponse login(@RequestBody LoginRequest loginRequest) {
		try {
			LoginResponse loginResponse = new LoginResponse();
			
			int resultCode = loginImpl.login(loginRequest, loginResponse);
			
			switch (resultCode) {
			case 0:
				loginResponse.setStatusCode(ResultCode.CODE_0);
				break;
			case 1:
				loginResponse.setStatusCode(ResultCode.CODE_1);
				break;

			default:
				break;
			}

			return loginResponse;
		} catch (Exception e) {
			System.out.println(e.toString());
		}

		return null;
	}

}
